<?php

namespace App;

use App\Http\Services\FileManager;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * App\Teacher
 *
 * @property int $id
 * @property int $photo_id 头像
 * @property string $name 姓名
 * @property string $phone 手机
 * @property string $email 邮箱
 * @property string $sex 男male,女female
 * @property string $area 地区
 * @property string $desc 简介
 * @property string|null $detail 详细介绍
 * @property string|null $deleted_at
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Teacher newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Teacher newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Teacher query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Teacher whereArea($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Teacher whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Teacher whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Teacher whereDesc($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Teacher whereDetail($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Teacher whereEmail($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Teacher whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Teacher whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Teacher wherePhone($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Teacher wherePhotoId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Teacher whereSex($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Teacher whereUpdatedAt($value)
 * @mixin \Eloquent
 * @method static bool|null forceDelete()
 * @method static \Illuminate\Database\Query\Builder|\App\Teacher onlyTrashed()
 * @method static bool|null restore()
 * @method static \Illuminate\Database\Query\Builder|\App\Teacher withTrashed()
 * @method static \Illuminate\Database\Query\Builder|\App\Teacher withoutTrashed()
 */
class Teacher extends Model
{
    use SoftDeletes;

    public static function getSex($sex){
        if(empty($sex))
            return '';

        switch ($sex){
            case 'male':
                return '男';
                break;
            case 'female':
                return '女';
                break;
            default:
                return '保密';
        }
    }

    public static function getTeacherInfo($id){
        if(empty($id))
            return '';

        $teacher = self::whereId($id)->first();
        if($teacher){
            $teacher->photo_url = FileManager::getImgUrl($teacher->photo_id);

            $teacher->sex_name = $teacher->getSex($teacher->sex);
        }

        return $teacher;
    }
}
